﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Swin_e_mon_Forms
{
    public class LookCommand: Command
    {
        public LookCommand(SwinEForm f)
            : base(new string[] {"look","Where am I"}, f)
        { }

        public override string Run(Player p, string[] input)
        {
            
            if (input[0].ToLower() == "where" && input[1].ToLower() == "am" && input[2].ToLower() == "i")
                return DoWhereAmI(p);
            else if (input.Length == 3 && input[0].ToLower() == "look" && input[1].ToLower() == "at")
                return DoLookAt(p, input[2]);
            else if (input.Length == 3 && input[0].ToLower() == "look" && input[1].ToLower() == "in")
                return DoLookIn(p, input[2]);
            else if (input.Length == 5 && input[0].ToLower() == "look" && input[1].ToLower() == "at" && input[3].ToLower() == "in")
                return DoLookAtIn(p, input[2], input[4]);
            else if (input[0].ToLower() == "look")
                return DoLook(p);

            return "I do not know how to look like that";
        }

        private string DoWhereAmI(Player p)
        {
            return p.InLocation.Title;
        }

        private string DoLook(Player p)
        {
            f.ClearLocList();
            foreach(Item itm in p.InLocation.Inventory.Items)
                f.AddToLocList(itm.Title + " (" + itm.mainIdentifier()+") ");
            return p.InLocation.LongDescription;
        }

        private string DoLookAt(Player p,string id)
        {
            GameEntity item = p.LocateEntity(id);
            if (item != null)
                return item.Description;
            else
                return "I can't find " + id;
        }

        private string DoLookIn(Player p, string id)
        {
            GameEntity item = p.LocateEntity(id);
            if (item != null)
                return item.LongDescription;
            else
                return "I can't find " + id;
        }

        private string DoLookAtIn(Player p, string id, string containerId)
        {
            GameEntity container = p.LocateEntity(containerId);
            if (container != null)
            {
                GameEntity item = container.LocateEntity(id);
                if (item != null)
                    return item.Description;
                return "I can't find " + id;
            }
            return "I can't find " + container;
        }
    }
}
